/*
 * Copyright 2025 arisgo@163.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.arisgo.cloud.auth.login.granter.impl;

import com.arisgo.cloud.auth.login.granter.AbstractLoginGranter;
import com.arisgo.cloud.auth.login.granter.GranterStore;
import com.arisgo.cloud.auth.login.model.Login;
import com.arisgo.cloud.auth.login.model.Type;
import com.arisgo.cloud.auth.sys.entity.User;
import com.arisgo.cloud.auth.sys.service.TenantService;
import com.arisgo.cloud.core.redis.UserInfo;
import com.arisgo.cloud.core.token.TokenGenerator;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 验证码登陆
 *
 * @author Arisgo
 * @since 2024/5/28
 */
@Component
public class CaptchaGranter extends AbstractLoginGranter implements InitializingBean {


    public CaptchaGranter(RedisTemplate<String, Object> redisTemplate,
                          TokenGenerator tokenGenerator,
                          TenantService tenantService) {
        super(redisTemplate, tokenGenerator, tenantService);
    }

    @Override
    protected UserInfo checkLogin(Login login) {
        return new UserInfo();
    }

    @Override
    public boolean register(Login login) {
        User user = new User();
        user.setAccount(login.getUsername());

//        user.setMobile();
        return false;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        GranterStore.register(Type.CAPTCHA.name(), this);
    }
}
